<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<body>

    <form layout:fragment="post-form">
        <div class="row-fluid">
            <div class="span8 blog-post--form">
                <input type="hidden" name="_method" value="PUT" th:if="${edit}" />
                <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>

                <div class="control-group" th:classappend="(${#fields.hasErrors('title')}? ' error')">
                    <label class="control-label" for="title">Title:</label>
                    <div class="controls">
                        <input id="title" type="text" th:field="*{title}" name="title" />
                        <span class="help-inline" th:if="${#fields.hasErrors('title')}" th:errors="*{title}">Incorrect title</span>
                    </div>
                </div>

                <div class="control-group" th:classappend="(${#fields.hasErrors('content')}? ' error')">
                    <label class="control-label" for="content">Content:</label>
                    <div class="controls">
                        <textarea id="content" th:field="*{content}" name="content"></textarea>
                        <span class="help-inline" th:if="${#fields.hasErrors('content')}" th:errors="*{content}">Incorrect content</span>
                    </div>
                </div>
                <div class="control-group">
                    <div class="help-block">Tips:
                        <ul>
                            <li>Be sure to wrap code blocks in <a href=" https://help.github.com/articles/github-flavored-markdown#syntax-highlighting">code fences</a> (including a language identifier).</li>
                            <li>All valid HTML tags are allowed, even script/iframe/style (to be used with great care...)</li>
                        </ul>
                    </div>
                </div>
                <div th:if="${create}">
                    <button name="draft" value="true" type="submit" class="btn btn-large">Create new Draft</button>
                </div>
                <div th:if="${edit}">
                    <button name="draft" th:if="*{!draft}" value="false" type="submit" class="btn btn-large btn-primary">Update</button>
                    <button name="draft" th:if="*{draft}" value="true" type="submit" class="btn btn-large btn-primary">Save</button>

                    <a th:href="${path}" th:if="*{draft}" target="_blank" class="btn btn-large btn-lg" role="button">Preview</a>

                    <div class="pull-right">
                        <button name="draft" th:if="*{!draft}" value="true" type="submit" class="btn btn-large btn-warning">Unpublish</button>
                        <button name="draft" th:if="*{draft}" value="false" type="submit" class="btn btn-large btn-warning">Publish</button>
                    </div>
                </div>

            </div>
            <div class="span4 blog-post-form--right-pane">
                <div class="control-group" th:classappend="(${#fields.hasErrors('category')}? ' error')">
                    <label class="control-label" for="category">Category:</label>
                    <div class="controls">
                        <select id="category" name="category" th:field="*{category}" >
                            <option th:each="cat : ${categories}" th:value="${cat.id}" th:text="${cat.displayName}">Category</option>
                        </select>
                        <span class="help-inline" th:if="${#fields.hasErrors('category')}" th:errors="*{category}">Incorrect category</span>
                    </div>
                </div>

                <div class="control-group" th:classappend="(${#fields.hasErrors('format')}? ' error')">
                    <label class="control-label" for="format">Format:</label>
                    <div class="controls">
                        <select id="format" name="format" th:field="*{format}" >
                            <option th:each="format : ${formats}" th:value="${format.id}" th:text="${format.displayName}">Format</option>
                        </select>
                        <span class="help-inline" th:if="${#fields.hasErrors('format')}" th:errors="*{format}">Incorrect format</span>
                    </div>
                </div>

                <!-- <div class="control-group inline" th:classappend="(${#fields.hasErrors('broadcast')}? ' error')">
                    <label class="control-label" for="broadcast">Broadcast:</label>
                    <div class="controls">
                        <input type="checkbox" th:field="*{broadcast}" id="broadcast" name="broadcast" />
                        <span class="help-inline" th:if="${#fields.hasErrors('broadcast')}" th:errors="*{broadcast}">Incorrect broadcast</span>
                    </div>
                </div> -->

                <div class="well">
                    <div class="control-group">
                        <div class="controls">
                            <div id="datetimepicker1" class="input-append date">
                                <input id="publishAt" type="text" th:field="*{publishAt}" name="publishAt" placeholder="Pick a Date" data-format="yyyy-MM-dd hh:mm" />
                                <span class="add-on">
                                  <i data-time-icon="icon-time" data-date-icon="icon-calendar">
                                  </i>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </form>
</body>
</html>
